<template>
  <div>
    <div id="main" style="width: 750px;height:400px;"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import _ from 'lodash'
export default {
  name: 'report',
  data() {
    return {
      reportData: '',
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  methods: {
    async getReportData() {
      const { data: res } = await this.$api.report.getReportsAPI()
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)

      this.reportData = _.merge(res.data, this.options)
      console.log(this.reportData)
    }
  },
  created() {
    this.getReportData()
  },
  watch: {
    reportData(newVal, oldVal) {
      // 基于准备好的dom，初始化echarts实例
      const myChart = echarts.init(document.getElementById('main'))
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(this.reportData)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
